#include<stdio.h>
#include<stdlib.h>

typedef struct Node {
	struct Node *children[26];
	int *data;
} Node;

Node *create_node()
{
	Node *t = (Node *) malloc(sizeof(Node));
	int i;
	for (i = 0; i < 26; i++) {
		t->children[i] = NULL;
	}
	t->data = NULL;
	return t;
}

Node *insert(Node * t, const char *key, int *value)
{
	int c;
	Node *p;
	if (!t) {
		t = create_node();
	}
	for (p = t; *key; ++key, p = p->children[c]) {
		c = *key - 'a';
		if (!p->children[c]) {
			p->children[c] = create_node();
		}
	}
	p->data = value;
	return t;
}

int *lookup(Node * t, const char *key)
{
	while (*key && t && t->children[*key - 'a']) {
		t = t->children[*key++ - 'a'];
	}
	return (*key || !t) ? NULL : t->data;
}

int main(int argc, char const *argv[])
{
	Node *t = create_node();
	char *ch[3] = { "we", "hello", "were" };

	char *pch = ch[0];
	int v[3] = { 1, 2, 3 };
	int i;
	for (i = 0; i < 3; i++) {
		insert(t, ch[i], v + i);
	}
	printf("%d\n", *lookup(t, ch[1]));
	return 0;
}
